
package org.springblade.modules.videoanswer.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.modules.system.entity.RoleMenu;
import org.springblade.modules.videoanswer.entity.Group;
import org.springblade.modules.videoanswer.entity.GroupVideo;
import org.springblade.modules.videoanswer.entity.QuestionItem;
import org.springblade.modules.videoanswer.service.IGroupService;
import org.springblade.modules.videoanswer.vo.GroupVideoVO;
import org.springblade.modules.videoanswer.mapper.GroupVideoMapper;
import org.springblade.modules.videoanswer.service.IGroupVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.ArrayList;
import java.util.List;

/**
 * 视频群组分配表 服务实现类
 *
 * @author jiangyandong
 * @since 2021-03-25
 */
@Service
public class GroupVideoServiceImpl extends ServiceImpl<GroupVideoMapper, GroupVideo> implements IGroupVideoService {

	@Autowired
	IGroupService groupService;

	@Override
	public IPage<GroupVideoVO> selectGroupVideoPage(IPage<GroupVideoVO> page, GroupVideoVO groupVideo) {
		return page.setRecords(baseMapper.selectGroupVideoPage(page, groupVideo));
	}

	@Override
	public boolean batchSubmit(List<GroupVideo> groupVideoList){
		if(groupVideoList != null && groupVideoList.size() > 0){
			this.saveOrUpdateBatch(groupVideoList);
		}
		return true;
	}

	@Override
	public List<Group> getGroupListByVideoid(Integer videoId){
		List<GroupVideo> groupVideos = this.list(Wrappers.<GroupVideo>query().lambda().eq(GroupVideo::getVideoId, videoId));
		List<Integer> groupIds = new ArrayList<>();
		for(GroupVideo groupVideo1 : groupVideos){
			groupIds.add(groupVideo1.getGroupId());
		}
		if(groupIds.size() > 0){
			List<Group> groupList = groupService.list(Wrappers.<Group>query().lambda().in(Group::getId,groupIds));
			return groupList;
		}
		return new ArrayList<>();
	}
	@Override
	public boolean removeGroupvideo(GroupVideo groupVideo){
		this.remove(Wrappers.<GroupVideo>update().lambda().eq(GroupVideo::getVideoId, groupVideo.getVideoId()).eq(GroupVideo::getGroupId,groupVideo.getGroupId()));
		return true;
	}
}
